﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MovieDbLib;
using MovieDbLib.Data;

namespace MovieDbBrowser
{
  /// <summary>
  /// Interaction logic for MovieSearch.xaml
  /// </summary>
  public partial class MovieSearch : Window
  {
    private MovieDbHandler m_handler;
    private int m_selectedMovie;

    public int SelectedMovie
    {
      get { return m_selectedMovie; }
    }
    public MovieSearch(MovieDbHandler _handler, String _searchString)
    {
      InitializeComponent();
      m_handler = _handler;
      List<MovieDbMovie> movieList = m_handler.SearchMovie(_searchString, null);
      lvMovies.ItemsSource = movieList;
    }

    private void lvMovies_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
      MovieDbMovie m = (MovieDbMovie)lvMovies.SelectedItem;
      m_selectedMovie = m.Id;
      txtId.Text = m.Id.ToString();
      txtName.Text = m.MovieName;
      txtOverview.Text = m.Overview;
    }

    private void cmdApply_Click(object sender, RoutedEventArgs e)
    {
      this.DialogResult = true;
    }
  }
}
